<template>
  <div class="visitor-services">
    <div class="content">
    <!-- 页面内容容器 -->
    <h1 class="main-title">游客服务</h1>
    <h2 class="mini-title">Visitor Services</h2>

    <div class="content-container">
      <!-- 服务导航卡片区 -->
      <el-row :gutter="40" class="service-card-grid">
        <!-- 参观指南卡片 -->
        <el-col :xs="24" :sm="12" :md="6" :lg="6">
          <service-card 
            class="service-card-container"
            title="参观指南"
            description="获取电子导览手册"
            @click="openGuideDialog"
            :card-style="{
              width:'200px',
              height:'150px',
              backgroundColor:'#E6F7FF',
              borderColor:'#BAE0FF',
              '--hover-shadow': '0 8px 20px rgba(186,224,255,0.3)'
            }"
          />
        </el-col>

        <!-- 入馆登记卡片 -->
        <el-col :xs="24" :sm="12" :md="6" :lg="6">
          <service-card 
            class="services-card-container"
            title="入馆登记"
            description="团队预约/个人登记"
            @click.native="showRegistrationForm = true"
            :card-style="{
              width:'200px',
              height:'150px',
               backgroundColor: '#FFE6E6',
               borderColor: '#FFCCCC',
               '--hover-shadow': '0 8px 20px rgba(255,204,204,0.3)'
            }"
          />
        </el-col>

        <!-- 讲解服务卡片 -->
        <el-col :xs="24" :sm="12" :md="6" :lg="6">
          <service-card 
            class="service-card-container"
            title="讲解服务"
            description="专业导览预约"
            @click.native="openGuideServiceDialog"
            :card-style="{
            width:'200px',
            height:'150px',
            backgroundColor: '#F4F4E1',
            borderColor: '#E6E6A2',
            '--hover-shadow': '0 8px 20px rgba(230,230,162,0.3)'
            }"
          />
        </el-col>

        <!-- 人流监控卡片 -->
        <el-col :xs="24" :sm="12" :md="6">
          <traffic-card 
              :count="visitorCount" 
              :percentage="trafficPercentage"
              :card-style="{
              width:'200px',
              height:'150px',
               backgroundColor: '#E6FFE6',
               borderColor: '#B8E6B8',
               '--hover-shadow': '0 8px 20px rgba(184,230,184,0.3)'
            }"
          />
        </el-col>
      </el-row>

      <!-- 功能模块区 -->
      <div class="module-container">
        <!-- 交通指南 -->
        <section class="content-section">
          <h2 class="section-title">
            交通指南
          </h2>
          <div class="section-content">
            <p>地址：XX市博物馆路8号</p>
            <p>地铁：4号线 博物馆站 A出口</p>
            <p>公交：101/103/108路 博物馆站</p>
            <div class="map-container">
              <!-- 嵌入地图组件 -->
              <iframe 
                src="https://maps.example.com/embed" 
                frameborder="0"
                class="map-iframe"
                :style="{height:isMobile ? '300px' : '400px'}"
                @load="onMapLoad"
              ></iframe>
            </div>
          </div>
        </section>

        <!-- 联系方式 -->
        <section class="content-section">
          <h2 class="section-title">
            联系方式
          </h2>
          <div class="section-content">
            <p>服务热线：400-123-4567（09:00-17:00）</p>
            <p>紧急联系：138-XXXX-XXXX</p>
            <p>邮箱：service@museum.com</p>
          </div>
        </section>

        <!-- 常见问题 -->
        <section class="content-section">
          <h2 class="section-title">
            常见问题
          </h2>
          <el-collapse 
            v-model="activeFAQ" 
            class="faq-collapse"
            accordion
          >
            <el-collapse-item 
              v-for="item in faqList"
              :key="item.id"
              :title="item.question"
              :name="item.id"
            >
              {{ item.answer }}
            </el-collapse-item>
          </el-collapse>
        </section>

        <!-- 打卡点展示 -->
        <section class="content-section">
          <h2 class="section-title">
            拍照打卡点
          </h2>
          <el-carousel 
            :interval="5000"
            arrow="always"
            height="300px"
            class="checkin-carousel"
          >
            <el-carousel-item 
              v-for="spot in checkinSpots"
              :key="spot.id"
            >
              <img 
                :src="spot.image" 
                alt="打卡点"
                class="checkin-image"
                loading="lazy"
                @error="handleImageError"
              >
              <h3 class="checkin-title">{{ spot.name }}</h3>
            </el-carousel-item>
          </el-carousel>
        </section>
      </div>

      <!-- 电子留言簿 -->
      <section class="guestbook-section">
        <h2 class="section-title">
          电子留言簿
        </h2>
        <el-input
          type="textarea"
          :rows="4"
          placeholder="留下您的宝贵意见..."
          v-model="guestbookMessage"
          class="guestbook-input"
        />
        <el-button 
          type="primary" 
          class="submit-btn"
          @click="submitGuestbook"
        >
          提交留言
        </el-button>
      </section>
    </div>

    <!-- 入馆登记表单 -->
    <el-dialog 
      title="入馆登记"
      :visible.sync="showRegistrationForm"
      width="600px"
      class="registration-dialog"
    >
      <el-form 
        :model="registrationForm" 
        :rules="rules"
        ref="registrationForm"
        label-width="100px"
        class="registration-form"
      >
        <el-form-item label="姓名" prop="name">
          <el-input v-model="registrationForm.name"/>
        </el-form-item>
        <el-form-item label="证件类型" prop="idType">
          <el-select v-model="registrationForm.idType">
            <el-option label="身份证" value="idCard"/>
            <el-option label="护照" value="passport"/>
          </el-select>
        </el-form-item>
        <el-form-item label="证件号" prop="idNumber">
          <el-input v-model="registrationForm.idNumber"/>
        </el-form-item>
        <el-form-item label="参观人数" prop="peopleCount">
          <el-input-number 
            v-model="registrationForm.peopleCount" 
            :min="1"
            class="people-counter"
          />
        </el-form-item>
      </el-form>
      <span slot="footer">
        <el-button @click="showRegistrationForm = false">取消</el-button>
        <el-button type="primary" @click="submitRegistration">
          提交
        </el-button>
      </span>
    </el-dialog>
    </div>
    <footer class="footer">
      <p>© 2025 历史博物馆. 版权所有.</p>
      <button class="back-to-top" @click="scrollToTop">回到顶部</button>
    </footer>
  </div>
</template>

<script>
import ServiceCard from '@/components/ServiceCard.vue'
import TrafficCard from '@/components/TrafficCard.vue'

export default {
  components: {
    ServiceCard,
    TrafficCard
  },
  data() {
    return {
      showRegistrationForm: false,
      guestbookMessage: '',
      visitorCount: 0,
      trafficPercentage: 0,
      activeFAQ: '1',
      isMobile:false,
      mapLoad:false,
      registrationForm: {
        name: '',
        idType: 'idCard',
        idNumber: '',
        peopleCount: 1
      },
      rules: {
      name: [
        { required: true, message: '请输入姓名', trigger: 'blur' }
      ],
      idNumber: [
        { required: true, message: '请输入证件号', trigger: 'blur' },
        { min: 15, max: 18, message: '证件号长度应为15-18位', trigger: 'blur' }
      ]
    },
      faqList: [
        {
          id: '1',
          question: '如何预约团队导览？',
          answer: '请至少提前3个工作日通过官网预约系统或致电服务热线预约'
        },
        {
          id: '2',
          question: '馆内提供哪些便民服务？',
          answer: '1F服务台提供免费轮椅/婴儿车租赁、行李寄存等服务'
        }
      ],
      checkinSpots: [
        {
          id: '1',
          name: '青铜之光',
          image: require('@/assets/carousel1.jpg')
        },
        {
          id: '2',
          name: '瓷器长廊',
          image: require('@/assets/carousel2.jpg')
        }
      ]
    };
  },
  computed: {
    trafficColor() {
      return this.trafficPercentage > 80 ? '#ff4757' : '#409EFF';
    }
  },
  mounted() {
    this.isMobile=window.innerWidth<=768
    window.addEventListener('resize',this.handleResize)

    // 模拟人流数据
    setInterval(() => {
      this.visitorCount = Math.floor(Math.random() * 500);
      this.trafficPercentage = Math.min((this.visitorCount / 800) * 100, 100);
    }, 5000);
  },
  beforeDestroy(){
      window.removeEventListener('resize',this.handleResize)
  },
  methods: {
    handleImageError(event) {
    event.target.src = require('@/assets/picture1.jpg')
  },
    openGuideDialog() {
      this.$alert('电子导览手册已发送至您的邮箱', '导览手册', {
        confirmButtonText: '确定'
      });
    },
    openGuideServiceDialog() {
      this.$alert('专业导览需提前3天预约，请致电400-123-4567', '导览预约', {
        confirmButtonText: '知道了'
      })
    },
    async submitRegistration() 
    {
      try {
    // 模拟API调用（替换为真实请求）
    await new Promise(resolve => setTimeout(resolve, 500))
    
    this.showRegistrationForm = false
    this.$message.success('登记成功！请持有效证件入馆')
    
    // 重置表单（使用Vue内置方法）
    this.$nextTick(() => {
      this.$refs.registrationForm.resetFields()
    })
  } catch (error) {
    console.error('提交失败:', error)
    this.$message.error('提交失败，请重试')
  }
    },
    submitGuestbook() {
      if(this.guestbookMessage.trim()) {
        this.$message.success('感谢您的留言！');
        this.guestbookMessage = '';
      }
    },
    handleResize(){
      this.isMobile=window.innerWidth<=768
    },
    onMapLoad(){
      this.mapLoaded=true
    },
    scrollToTop() {
    window.scrollTo({
      top: 0,
      behavior: 'smooth'
    })
  }
  }
};
</script>

<style scoped>
.visitor-services::before{
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('@/assets/background.jpg') repeat-x center/cover;
    z-index: -1;
    opacity: 0.3;
}

.visitor-services{
  position: relative;
  min-height: 100vh;
}

.content{
  position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 40px 20px;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(5px);
}

.main-title {
  font-size: 30pt;
    color: #333;
    margin-bottom: 10px;
}

.mini-title{
  font-size: 12pt;
    color: gray;
    margin: 10px 0 40px;
}

.content-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 120px 20px 60px; /* 修改1：减少顶部padding */
  position: relative;
  z-index: 1;
  min-height: 100vh; /* 确保页面最小高度 */
}

.service-card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

.service-card {
  position: relative;
  overflow: visible; /* 允许内容溢出 */
  padding: 25px;     /* 增加内边距 */
  min-height: 180px; /* 保持最小高度 */
  display: flex;     /* 使用flex布局 */
  flex-direction: column;
  justify-content: space-between; /* 上下分布内容 */
}
 
.service-card-container {
  min-width: 200px; /* 保证最小宽度 */
  width: 100%;
  height: 100%;
  transition: all 0.3s ease;
}

.service-card:hover {
  /* 增强悬停效果 */
  transform: translateY(-5px);
  box-shadow: var(--hover-shadow, 0 8px 20px rgba(0,0,0,0.08));
  border-color: transparent;
}
 
/* 添加点击波纹效果 */
.service-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle, 
    rgba(255,255,255,0.2) 0%,
    rgba(255,255,255,0) 70%
  );
  opacity: 0;
  transition: opacity 0.3s;
}
 
.service-card:active::after {
  opacity: 1;
}

.module-container {
  max-width: 960px;
  margin: 0 auto;
}

.content-section {
  margin-bottom: 60px;
  padding: 30px;
  background: rgba(255,255,255,0.95);
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.section-title {
  margin-left: 0;
  padding-left: 0;
}

.map-container {
  transition: height 0.3s;
  border: 1px solid #eee;
  &.full-height{
    height: 300px;
  }
  margin-top: 20px;
  border-radius: 8px;
  overflow: hidden;
}

.map-iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.faq-collapse {
  margin-top: 20px;
}

.checkin-carousel {
  border-radius: 8px;
  overflow: hidden;
}

.checkin-image {
  width: 100%;
  height: 300px;
  object-fit: cover;
}

.checkin-title {
  position: absolute;
  bottom: 20px;
  left: 20px;
  color: white;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.guestbook-section {
  max-width: 800px;
  margin: 0 auto 60px;
}

.guestbook-input {
  margin: 20px 0;
}

.submit-btn {
  float: right;
}

/* 底边栏 */
.footer {
  background: #333333;
  color: white;
  border-top: 2px solid #4D4D4D;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  box-sizing: border-box;
  backdrop-filter: blur(5px);
  width: 100%; /* 确保全宽 */
  margin-top: auto; /* 将footer推到页面底部 */
}
 
.back-to-top {
  padding: 8px 16px;
  background: #555555;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 14px;
  min-width: 100px;
}
 
.back-to-top:hover {
  background: #666666;
  transform: translateY(-1px);
}

@media (max-width: 1200px) {
  .service-card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1200px) {
  .service-card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .content-container {
    padding: 200px 15px 40px;
  }

  .service-card-grid {
    grid-template-columns: 1fr;
  }

  .service-card {
    padding: 20px;
    min-height: 160px;
  }
  
  .card-title {
    font-size: 18px;
    margin-bottom: 12px;
    line-height: 1.4;
    word-break: break-word; /* 允许单词换行 */
  }
  
  .card-description {
    font-size: 14px;
    color: #666;
    line-height: 1.6;
    min-height: 40px; /* 保证描述区域最小高度 */
  }

  .content-section {
    margin-bottom: 40px;
    padding: 20px;
  }

  .map-container {
    height: 200px;
  }

  .checkin-image {
    height: 200px;
  }

  .footer {
    flex-wrap: wrap;
    padding: 12px 10px;
    gap: 10px;
  }
  
  .back-to-top {
    min-width: auto;
    width: calc(50% - 10px);
  }
}

</style>